package com.zut.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zut.commonutils.R;
import com.zut.eduservice.entity.Verifytable;
import com.zut.eduservice.service.VerifytableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-12-31
 */
@RestController
@RequestMapping("/eduservice/verifytable")
@CrossOrigin
public class VerifytableController {
    @Autowired
    private VerifytableService verifytableService;
    //添加方法接口
    @PostMapping("addVerifytable")
    public R addVerfyTable(@RequestBody Verifytable verifytable) {

            boolean save = verifytableService.save(verifytable);

            if (save) {
                return R.ok();
            } else {
                return R.error();
            }
    }

    //条件分页查询
    @PostMapping("pageInformationCondition/{current}/{limit}")
    public R pageEvidenceCondition(@PathVariable long current, @PathVariable long limit
                                 ) {
        //创建page对象
        Page<Verifytable> pageInformation = new Page<>(current,limit);

        //构建条件
        QueryWrapper<Verifytable> wrapper =new QueryWrapper<>();
        verifytableService.page(pageInformation,wrapper);
        long total = pageInformation.getTotal();
        List<Verifytable> records= pageInformation.getRecords();
        return R.ok().data("total",total).data("records",records);
    }


}

